/** * Se da un labirint sub forma de matrice cu m linii si n coloane. * Fiecare element al matricei reprezinta o camera a labirintului. * Într-una din camere, de coordonate x si y, se gaseste un om. * Se cere sa se gaseasca toate iesirile din labirint. * */ #include #include #include #define in_filename ("labirint.txt") #define trap ('*') #define space (' ') #define me(x) ((x)==trap||(x)=='x'||(x)=='X') #define empty(x) ((x)==space||(x)=='0'||me(x)) #define _N 30 #define _UP 1 #define _RIGHT 2 #define _DOWN 4 #define _LEFT 8 typedef char tCell; typedef tCell tRow[_N]; typedef tRow tMap[_N]; typedef unsigned tSize; typedef tSize tSol[100][2]; tMap map, dmap; tSol sol; tSize m,n; int x,y; int read_lab(char *fn); void print_lab(tMap map); int ies(int x, int y, int k); int main() { clrscr(); if(!read_lab(in_filename)) { printf("Nu exista fisierul %s!\n", in_filename); return 1; } printf("\nHarta (%dx%d):\n", n, m); print_lab(map); while(x < 0 || y < 0) { printf("\nPozitia (x, y):"); scanf("%d %d", &x, &y); x--; y--; if(!empty(map[y][x]) || x >= n || y >= m) { printf("Perete!"); x = -1; } } printf("\nHarta directiilor codificate hex:\n"); print_lab(dmap); getch(); printf("\nSolutii:\n"); if(!ies(x,y,0)) { printf("\nNu sunt solutii :-(\n"); getch(); } return 0; } char tonr(tCell c) { if( 0 <= c && c <= 9) return c + '0'; if(10 <= c && c <= 15) return c + 'A' - 10; return c; } void print_lab(tMap map) { tSize i,j; for(i = 0; i < m; i++) { for(j = 0; j < n; j++) printf("%c", tonr(map[i][j])); printf("\n"); } } void tipar(int k) { int i; printf("--------------\n"); for(i=0; in) n = i; m++; map[m][0] = 0; } fclose(f); norm_lab(); return 1; } else return 0; }